package com.lb.jwitter.action;

import java.util.ArrayList;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.lb.jwitter.service.ConditionReport;
import com.lb.jwitter.service.TblQuyenChiTietService;
import com.lb.jwitter.service.TblTaiKhoan;
import com.lb.jwitter.service.TblDKMHCamHoacQuyDinh;
import com.lb.jwitter.service.TblDKMHCamHoacQuyDinhService;
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;

import com.lb.jwitter.service.TblThongTinHocVien;
import com.lb.jwitter.service.TblThongTinHocVienService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

import com.lb.jwitter.service.TblCanBo;
import com.lb.jwitter.service.TblCanBoService;

/**
 * @author QUOCVIET
 * 
 */

@ContextConfiguration(locations = "classpath:beans.xml")
public class TblDKMHCamHoacQuyDinhFormAction {
	private int pageSize;

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	private int page;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	private int pages;

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	private String dataString;

	public String getDataString() {
		return dataString;
	}

	private Collection<TblDKMHCamHoacQuyDinh> tblDKMHCamHoacQuyDinhs;

	public Collection<TblDKMHCamHoacQuyDinh> getTblDKMHCamHoacQuyDinhs() {
		return tblDKMHCamHoacQuyDinhs;
	}

	private TblDKMHCamHoacQuyDinhService tblDKMHCamHoacQuyDinhService;

	private Collection<TblDKMHDotDK> tblDKMHDotDKs;

	public Collection<TblDKMHDotDK> getTblDKMHDotDKs() {
		return tblDKMHDotDKs;
	}

	private TblDKMHDotDKService tblDKMHDotDKService;

	private Collection<TblThongTinHocVien> tblThongTinHocViens;

	public Collection<TblThongTinHocVien> getTblThongTinHocViens() {
		return tblThongTinHocViens;
	}

	private TblThongTinHocVienService tblThongTinHocVienService;

	private Collection<TblCTDTMonHoc> tblCTDTMonHocs;

	public Collection<TblCTDTMonHoc> getTblCTDTMonHocs() {
		return tblCTDTMonHocs;
	}

	private TblCTDTMonHocService tblCTDTMonHocService;

	private Collection<TblCanBo> tblCanBos;

	public Collection<TblCanBo> getTblCanBos() {
		return tblCanBos;
	}

	private TblCanBoService tblCanBoService;

	private TblTaiKhoan taiKhoanDangNhap;

	public TblTaiKhoan getTaiKhoanDangNhap() {
		return taiKhoanDangNhap;
	}

	public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) {
		this.taiKhoanDangNhap = taiKhoanDangNhap;
	}

	private TblQuyenChiTietService tblQuyenChiTietService;
	@Autowired
	// Injected by Spring
	ApplicationContextProvider contextProvider;

	public String execute() throws Exception {
		try {
			Map session = ActionContext.getContext().getSession();
			taiKhoanDangNhap = (TblTaiKhoan) session.get("taiKhoan");
			if (taiKhoanDangNhap == null)
				return "noprivilege";
			ApplicationContext context = ApplicationContextProvider
					.getApplicationContext();
			tblQuyenChiTietService = (TblQuyenChiTietService) context
					.getBean("tbl_Quyen_ChiTietClient");
			if (!tblQuyenChiTietService
					.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(),
							"tbl_DKMH_CamHoacQuyDinh", "xem")) {
				return "noprivilege";
			}
			tblDKMHCamHoacQuyDinhService = (TblDKMHCamHoacQuyDinhService) context.getBean("tbl_DKMH_CamHoacQuyDinhClient");
			tblDKMHDotDKService = (TblDKMHDotDKService) context.getBean("tbl_DKMH_DotDKClient");

			if (pageSize == 0) {
				pageSize = 20;
			}
			if (page == 0) {
				page = 1;
			}
			tblDKMHCamHoacQuyDinhs = tblDKMHCamHoacQuyDinhService.findAlltblDKMHCamHoacQuyDinh(pageSize, page);
			pages = tblDKMHCamHoacQuyDinhService.counttblDKMHCamHoacQuyDinhByCondition(new ArrayList<ConditionReport>())/ pageSize + 1;
			dataString = "";
			dataString += "&dotDKId=";
			dataString += "&hocVienId=";
			dataString += "&monHocId=";
			dataString += "&maTinhNang=";
			tblDKMHDotDKs = tblDKMHDotDKService.findAlltblDKMHDotDK(20, 1);
			return Action.SUCCESS;
		} catch (Exception e) {
			System.out.println("Loi Form tbl_DKMH_CamHoacQuyDinh Action");
			e.printStackTrace();
			return Action.ERROR;
		}
	}
}
